/**
 * Merchant Page
 */

import expired from '@/config/expired'
import * as cache from '@/util/cache'
import md5 from 'js-md5'
const key = 'M' + md5('merchant')

export default {
  namespaced: true,
  state: {
    merchant: null
  },
  getters: {
    merchant: state => {
      if (state.merchant === null) {
        state.merchant = cache.get(key)
      }
      return state.merchant
    }
  },
  mutations: {
    SET_DATA: (state, data) => {
      state.merchant = data
      cache.save(key, data, expired.merchantTypeExpired)
    }
  },
  actions: {
    set_data: ({ commit }, data) => {
      commit('SET_DATA', data)
    }
  }
}
